package CasosTestIntra;

public class C {

    private C f1;
    private C f2;

   /**
     * Test 1
     *
     * copy+store
     */
    public void m_00() {
        C x = new C();
        C z = new C();
        x = z;
        // x.f1 == x ? SI
        // x may-alias z? SI
        // x.f2 !=null? NO
    }
    /**
     * Test 1
     *
     * copy+store
     */
    public void m_01() {
        C x = new C();
        C z = x;
        z.f1 = x;
        // x.f1 == x ? SI
        // x may-alias z? SI
        // x.f2 !=null? NO
    }

    /**
     * Test 2
     *
     * store
     */
    public void m_02() {
        C x = new C();
        C y = new C();
        x.f1 = y;
        // x may-alias y? NO
        // x.f1 == y? SI
    }

    /**
     * Test 3
     *
     * store+load
     */
    public void m_03(int k, int h) {
        C x = new C();
        C y = new C();
        x.f1 = y;
        C temp = x.f1;
        y.f1 = temp;
        // x may-alias y? NO
        // y.f1 == y? SI
    }

    /**
     * Test 4
     *
     * 3-chain
     */
    public void m_04() {
        C x = new C();
        C y = new C();
        C z = new C();
        x.f1 = y;
        y.f1 = z;
        z.f1 = x;

        C t = z;
        t = t.f1;
        t = t.f1;
        // may_reach(z, f1+f2).has(z) ? SI
        // t may-alias y? SI
        // t may-alias x? NO
    }

    /**
     * Test 5
     *
     * branch
     */
    public void m_05(int k) {
        C x = new C();
        C y = new C();
        C z = new C();

        if (k > 0) {
            x.f1 = y;
        } else {
            x.f1 = z;
        }
        // x.f1 may-alias x ? NO
        // x.f1 may-alias y ? SI
        // x.f1 may-alias z ? SI
    }

    /**
     * Test 6
     *
     * finite loop
     */
    public void m_06(int k) {
        C x = new C();
        C ptr = x;

        if (k < 0) {
            k = -k;
        }

        for (int i = 0; i < k; i++) {
            C t = new C();
            ptr.f1 = t;
            ptr = t;
        }
        // x == null? NO
        // may_reach(x,f1+f2).has(x)? NO
        // x.f1 maybe null? SI
        // t.f1 maybe null? SI
        // t.f1 maybe not-null? SI
    }

    /**
     * Test 7
     *
     * store null
     */
    public void m_07() {
        C x = new C();
        x.f1 = x;
        x.f1 = null;
        // x.f1 == null? NO
        // x.f1 != null? NO
        // x.f1 maybe null? SI
        // x.f1 maybe not-null? SI
    }

    /**
     * Test 8
     *
     * copy null
     */
    public void m_08() {
        C x = new C();
        x.f1 = x;
        x = null;
        // x == null? SI
        // x.f1 maybe null? falla
        // x.f1 maybe not-null? falla

    }

    /**
     * Test 9
     *
     * escape 2-chain
     */
    public C m_09() {
        C x = new C();
        C y = new C();
        x.f1 = y;
        return x;
        // el objeto creado en la linea 57 escapa?
        // (es alcanzable desde el return o un parametro) SI
    }

    /**
     * Test 10
     *
     * method invokation
     */
    public void m_10() {
        C x = new C();
        x.m_01();
        x.m_02();
        x.f1 = x;
        // W is empty? NO
        // m_01  && m_02 in W? SI
    }

    /**
     * Test 11
     *
     * 2 fields / store
     */
    public void m_11() {
        C x = new C();
        C y = new C();
        C z = new C();
        x.f1 = y;
        x.f2 = z;

        z.f1 = x;
        y.f2 = x;
        // may_reach(y,f1+f2).has(z)? SI
        // may_reach(x,f1).has(z)? NO
    }

    /**
     * Test 12
     *
     * 2 fields / store+load
     */
    public void m_12() {
        C x = new C();
        C y = new C();
        C z = new C();
        x.f1 = y;
        x.f2 = z;

        C t_y = x.f1;
        C t_z = x.f2;

        t_z.f1 = x;
        t_y.f2 = x;
        // t_y may-alias y? SI
        // t_z may-alias y? NO
        // may_reach(x,f1+f2).has(x)? SI
        // may_reach(x,f2).has(x)? NO
    }

    /**
     * Test 13
     *
     * branch
     */
    public void m_13(int k) {
        C x = new C();
        C y = new C();
        C z = new C();

        if (k > 0) {
            x.f1 = y;
        } else {
            x.f1 = z;
        }
        C t = x.f1;
        t.f2 = x;
        // y.f2 may-alias x ? SI
        // z.f2 may-alias x ? SI
        // may_reach(x, f1).has(x)? NO
    }

    public void m_14(int k) {
        C x = new C();
        C y = new C();
        C z = new C();
        x = null;


        if (k > 0) {
            x = y;
        } else {
            x = z;
        }

        C h = new C();
        x.f1 = h;
        // y.f1 may-alias h ? SI
        // z.f1 may-alias h ? SI
        // h may-alias x ? NO
    }
}
